package com.japp.sys.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.japp.base.BaseService;
import com.japp.sys.bean.DpBean;
import com.japp.sys.bean.SelectBean;
import com.japp.sys.mapper.DpMapper;
import com.japp.tools.page.Page;

/**
 * 
 * @author Jion
 *角色管理
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DpService implements BaseService {
	@Autowired
	private DpMapper dpMapper;
	
	
	/**
	 * 分页查询
	 * @param page
	 * @param obj
	 * @return
	 */
	public Page<DpBean> getPage(Page<DpBean> page,DpBean obj){
		return dpMapper.getPage(page, obj);
	}
	
	/**
	 * 查询所有角色
	 * @return
	 */
	public List<DpBean> queryDpAll() {
		return dpMapper.queryDpAll();
	}

	public List<SelectBean> queryDpSelectAll(){
		return dpMapper.queryDpSelectAll();
	}
	public List<SelectBean> queryDpSelectAllCode(){
		return dpMapper.queryDpSelectAllCode();
	}
	/**
	 * 查询角色（ID）
	 * @return
	 */
	public DpBean findDpById(int id) {
		return dpMapper.findDpById(id);
	}
	/**
	 * 更新角色
	 * @return
	 */
	public int updateDp(DpBean dp) {
		int rel = 0;
		try {
			rel = dpMapper.updateDp(dp);
		} catch (Exception e) {
			if(e.getCause().getMessage().indexOf("违反唯一约束")!=-1){
				rel = 999;
				return rel;
			}
			rel = 0;
		}
		return rel;
	}
	/**
	 * 添加角色
	 * @return
	 */
	public int insertDp(DpBean dp) {
		int rel = 0;
		try {
			rel = dpMapper.insertDp(dp);
		} catch (Exception e) {
			if(e.getCause().getMessage().indexOf("违反唯一约束")!=-1){
				rel = 999;
				return rel;
			}
			rel = 0;
		}
		return rel;
	}
	/**
	 * 删除角色
	 * @return
	 */
	public int deleteDpById(String[] keys) {
		int rel = 0;
		if(keys!=null&&keys.length>0){
			rel = dpMapper.deleteDpById(keys);
		}
		return rel;
	}
}
